package com.szkingdom.kfit.bank.cmbcxm.util;

import com.szkingdom.kfit.bank.common.config.SystemConfig;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by shaorui on 2016-7-27.
 */
public class CmbXMUtil {
   // private static int serial = 0;
    private static char base[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

    private static long serial = 127;

    private static long bIndex = 0;
    private static final Object object = new Object();
    /**
	* 生成固定位数的随机数
	*/
    public static String getAppSerialNo(int length) {
        double max = Math.pow(10,length);
        String curSerial;
        synchronized (object){
            if (++bIndex >= max) {
                bIndex = 0;
            }
            curSerial = bIndex + "";
        }
        while (curSerial.length() < length) {
            curSerial = "0" + curSerial;
        }
        return curSerial;
    }
    /**
	* 得到下一天
	*/
    public static String  getNextDay(String dateString){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        Date date=null;
        try {
            date=sdf.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        date = calendar.getTime();
        return sdf.format(date);
    }


    public static boolean isCmbBranch(String branchCode)
    {
        String []cmbcDranchCode=  SystemConfig.getProperty("cmbbankxm.branch_code").split(",");
        for(int i=0;i<cmbcDranchCode.length;i++){
            if(cmbcDranchCode[i].equals(branchCode)){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        SimpleDateFormat dayformat = new SimpleDateFormat("yyyyMMddHHmmss");

        System.out.println(dayformat.format(new Date()+CmbXMUtil.getAppSerialNo(6)));

    }
}
